<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglib.jsp" %>    
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script>
	//# sourceURL=caUserList.js
	
	var selUserId = null;
	var selUserName = null;

	$(document).ready(function() {

		// 选择表格行
		$("#gridCaUser table > tbody > tr").click(function() {
			$("#gridCaUser table > tbody > tr").removeClass('info');
			$(this).addClass('info');
			selUserId = $(this)[0].id;
			selUserName = $(this).find("td").eq(0).text();
		});
		
		// 模态框退出后，清空
// 		$('#dialog_main').on('hide.bs.modal', function() {
// 			//alert('hide dialog');
// 			$(this).removeData("bs.modal");
// 			$(this).find(".modal-content").empty();
// 		});

	});

	function addUser() {
		$('#dialog_main').modal({
			keyboard: false,
			remote: '${ctx}/ca/userAdd.action'
		});
	}

	function editUser() {
		if (checkSelected() == false) return;
		$('#dialog_main').modal({
			keyboard: false,
			remote: '${ctx}/ca/userModify.action?userId=' + selUserId
		});		
	}

	function changeState(state) {
		if (checkSelected() == false) return;
		
		if(state == "Delete" && confirm('确定要删除"' + selUserName + '"吗？') == false) {
			return;
		}
		
		var url = "${ctx}/ca/changeState.action?userId=" + selUserId + "&validState=" + state;
		$.get(url, function(data) {	    				    		
			if(data == "success") {
				refreshPage();
			} else {
				alert("错误: \n" + data);
			}
		})
		.error(function(xmlHttpRequest, textStatus, errorThrown) { 
			  alert("异常： " + xmlHttpRequest.status + ":" + errorThrown);
		});			
	}

	function resetPassword() {
		if (checkSelected() == false) return;
		
		var url = "${ctx}/ca/resetPassword.action?userId=" + selUserId;
		$.get(url, function(data) {
			if(data == "success") {
				alert("密码重置成功");
			} else {
				alert("错误: \n" + data);
			}
		})
		.error(function(xmlHttpRequest, textStatus, errorThrown) { 
			  alert("异常： " + xmlHttpRequest.status + ":" + errorThrown);
		});	
	}

	function checkSelected() {
		if (selUserId == null) {
			alert("请选择表格行");
			return false;
		} else {
			return true;
		}
	}
	
	function dialogSubmitSuccess() {
		$('#dialog_main').modal('hide');
		refreshPage();
	}
	
    function refreshPage(n) {
		var url = "/ca/userManage.action?pageIndex=${mtrPage.pageIndex}";
		if (typeof n != "undefined") {
			url = "/ca/userManage.action?pageIndex=" + n;
		}
		
		load_main_content(url);
    }
    
	function onPageClick(n) {
		refreshPage(n);
	}    
        
</script>

</head>
<body>

<div>
	<h3>CA用户管理</h3>
</div>

<nav class="navbar navbar-default" role="navigation">
  <ul class="nav navbar-nav navbar-left">
    <li>
      <a href="javascript:addUser()">新建</a></li>
    <li>
      <a href="javascript:editUser()">编辑</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">更多
        <b class="caret"></b></a>
      <ul class="dropdown-menu">
        <li>
          <a href="javascript:changeState('Invalid')">禁用</a></li>
        <li>
          <a href="javascript:changeState('Normal')">启用</a></li>
        <li class="divider"></li>
	    <li>
	      <a href="javascript:changeState('Delete')">删除</a></li>
        <li class="divider"></li>
        <li>
          <a href="javascript:resetPassword()">重置密码</a></li>
      </ul>
    </li>
  </ul>
</nav>

<div id="gridCaUser" class="table-responsive">
  <table class="table table-hover table-bordered">
    <thead>
      <tr>
        <th>用户名</th>
        <th>邮箱</th>
        <th>手机</th>
        <th>审批</th>
        <th>状态</th>
        <th>创建时间</th></tr>
    </thead>
    <tbody>
		<c:forEach items="${listUser}" var="node" varStatus="status">
			<tr id='${node.userId}'>
			<td>${node.userName}</td>
			<td>${node.email}</td>
			<td>${node.mobile}</td>
			<td>${node.isApprove ? "是" : "否"}</td>
			<td>${node.displayValidState}</td>
			<td><fmt:formatDate value="${node.createTime}" pattern="yyyy-MM-dd HH:mm"/></td>
			</tr>
		</c:forEach>
    </tbody>
  </table>
</div>

<%@ include file="/WEB-INF/view/common/bootstrapPage.jsp" %>

<!-- <div class="clearfix">
  <div class="col-md-6 column" style="background-color:white;text-align: left;">当前显示1~20条,共161条</div>
  <div class="col-md-6 column" style="background-color:white;text-align: right;">
    <ul class="pagination" style="margin-top: 0px;margin-bottom: 10px;">
      <li>
        <a href="#">&laquo;</a></li>
      <li class="active">
        <a href="#">1</a></li>
      <li>
        <a href="#">2</a></li>
      <li>
        <a href="#">3</a></li>
      <li>
        <a href="#">4</a></li>
      <li>
        <a href="#">5</a></li>
      <li>
        <a href="#">..</a></li>
      <li>
        <a href="#">&raquo;</a></li>
    </ul>
  </div>
</div> -->

<!-- <div class="modal" id="dialogCaUser">
    <div class="modal-dialog" style="width:600px;">
        <div id="dialogCaUser_content" class="modal-content">
          
        </div>
    </div>
</div> -->

</body>
</html>